import requests
import lxml
from lxml import etree
import re
import json

username = "d2356162166"
password = "l7zee1jn"
# 代理
proxies = {
    "http": f"http://{username}:{password}@36.156.102.17:31166",
    "https": f"http://{username}:{password}@36.156.102.17:31166",
}
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'
}
response = requests.get('https://www.xiachufang.com/explore/', proxies=proxies, headers=headers)
url = response.content.decode('utf-8')
print(url)
results = etree.HTML(url).xpath("//ul[@class='list']/li")
for result in results:
    names = result.xpath('.//p[@class="name"]/a/text()')
    ingredients = result.xpath('.//p[@class="ing ellipsis"]//text()')
    names = re.sub(r"\s", "", names[0])
    ingredients = "".join(ingredients)
    ingredients = ingredients.strip()
    print(names, ingredients)
